Skip to content

feat: global variables in Elixir - #1

Merged
fahad19 merged 2 commits into
mainfrom
top-vars
Aug 29, 2026
Merged

feat: global variables in Elixir#1
fahad19 merged 2 commits into
mainfrom
top-vars

Conversation

@fahad19

@fahad19 fahad19 commented Aug 29, 2026

Copy link
Copy Markdown
Member

What's done

This PR aligns the Featurevisor Elixir SDK with the latest JavaScript SDK behaviour and prepares its first stable release as Elixir SDK v1.

It adds complete support for global variables, updates feature dependency evaluation, aligns sticky state and lifecycle modules, improves datafile change events, extends the CLI, and substantially expands conformance coverage.

What changed

Global variables

  • Added support for independently defined global variables.
  • Added explicit evaluate_global_variable and get_global_variable APIs.
  • Added Boolean, string, integer, double, array, object, and JSON helpers.
  • Added get_global_variable_keys.
  • Added get_global_variable_evaluations for aggregate global variable evaluation.
  • Added support for caller defaults, sticky values, ordered and nested overrides, conditions, segments, and requiredFeatures.
  • Included override keys and nested override paths in evaluation details.
  • Added equivalent global variable support to child instances.

Example:

message = Featurevisor.get_global_variable_string(f, "welcomeMessage", context)
settings = Featurevisor.get_global_variable(f, "checkoutSettings", context)
evaluation = Featurevisor.evaluate_global_variable(f, "checkoutSettings", context)

Required features

  • Added the canonical requiredFeatures datafile model.
  • Supported required feature checks using enabled state, variation, or both.
  • Applied required feature checks to features, feature variables, global variables, and variable overrides.
  • Ensured required feature evaluations pass through the complete module pipeline.
  • Added the required_features_unmet evaluation reason and corresponding metadata.

Sticky features and variables

  • Split sticky state into sticky_features and sticky_variables.
  • Added set_sticky_features and set_sticky_variables.
  • Added sticky_features_set and sticky_variables_set events.
  • Added separate sticky feature and global variable support to child instances.
  • Aligned sticky replacement and inheritance behaviour with the JavaScript SDK.

Aggregate evaluations

  • Added get_feature_evaluations for feature snapshots.
  • Added get_global_variable_evaluations for global variable snapshots.
  • Added support for selecting specific feature or global variable keys.
  • Applied context and caller override options consistently.

Evaluation modules

  • Added before_evaluation and after_evaluation callbacks that work with both feature and global variable evaluations.
  • Preserved feature specific before and after callbacks.
  • Defined deterministic callback ordering.
  • Ensured required feature checks use the complete module pipeline.
  • Preserved transformed caller defaults through evaluation.

Datafile updates and events

  • Added global variables to datafile parsing, merging, and replacement.
  • Added dependency aware change detection across features, segments, required features, and global variables.
  • Updated datafile_set events to report affected feature and global variable keys.
  • Kept partial datafile update behaviour aligned with the JavaScript SDK.

CLI and integration

  • Added global variable support to the test and benchmark commands.
  • Added support for sticky global variables in project assertions.
  • Added global variable evaluation metadata to CLI output.
  • Expanded the shared SDK v3 conformance fixture and tests.
  • Preserved the idiomatic Mix escript workflow.

Elixir runtime behaviour

  • Kept instance state managed through isolated Elixir processes.
  • Added global variable and sticky state handling to the server snapshot.
  • Preserved process-safe concurrent evaluation.
  • Added child instance support through idiomatic Agent-backed state.
  • Kept public callbacks and option maps idiomatic through snake case keys.

Breaking changes

  • The Hex package version is now 1.0.0.
  • Sticky APIs now distinguish between features and global variables.
  • Aggregate feature evaluations use get_feature_evaluations.
  • Global aggregate evaluations use get_global_variable_evaluations.
  • Events, evaluation details, and public data structures have been aligned with the latest JavaScript SDK.
  • Datafile dependency declarations use requiredFeatures.

Install the SDK with:

def deps do
  [
    {:featurevisor, "~> 1.0"}
  ]
end

Verification

  • Elixir SDK unit and integration tests.
  • CLI tests.
  • Shared Featurevisor SDK v3 conformance suite.
  • Global variable and requiredFeatures alignment tests.
  • Module ordering and transformed default tests.
  • Child instance tests.
  • Datafile event dependency tests.
  • Formatting validation.
  • Credo strict checks.
  • Dialyzer analysis.
  • Documentation build.
  • Hex package content verification.
  • Supported Elixir and OTP version matrix.
  • example-1 integration through the Featurevisor CLI.

Release

This PR prepares the Hex package for tag:

v1.0.0

The tag workflow validates the package and publishes featurevisor to Hex.pm.

@fahad19 fahad19 self-assigned this Aug 29, 2026
@fahad19
fahad19 merged commit 59786ac into main Aug 29, 2026
6 checks passed
@fahad19
fahad19 deleted the top-vars branch August 29, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant